import streamlit as st
import pandas as pd
import numpy as np
import datetime

st.set_page_config(
    page_title="2.1NR",
    page_icon="✔",
    layout="wide",
    initial_sidebar_state="auto"
)

st.title(':violet[到场情况]')

df = pd.read_excel('./output/打卡.xlsx')
df['时间'] = df['时间'].astype(str).apply(lambda x:x.split(' ')[0])
time = str(datetime.datetime.now().strftime('%Y-%m-%d'))

df1 = df.query(f"时间=='{time}' & 单位=='中通'")
df2 = df.query(f"时间=='{time}' & 单位=='市工程'")
df3 = df.query(f"时间=='{time}' & 单位=='中通建'")
df4 = df.query(f"时间=='{time}' & 单位=='长讯'")


col1, col2, col3, col4, col5, col6, col7, col8 = st.columns(8)
with col1:
    col1.metric(label='中通', value=f'{df1.shape[0]} 队')
    # c1 = st.checkbox(label='', value=True, key='中通')  #checkbox方式
    c1 = st.toggle(label='', value='True')      #toggle方式
with col2:
    col2.metric(label='市工程', value=f'{df2.shape[0]} 队')
    # c2 = st.checkbox(label='', value=True, key='市工程') #checkbox方式
    c2 = st.toggle(label=' ', value='True')     #toggle方式
with col3:
    col3.metric(label='中通建', value=f'{df3.shape[0]} 队')
    # c3 = st.checkbox(label='', value=True, key='中通建') #checkbox方式
    c3 = st.toggle(label='  ', value='True')    #toggle方式
with col4:
    col4.metric(label='长讯', value=f'{df4.shape[0]} 队')
    # c4 = st.checkbox(label='', value=True, key='长讯')  #checkbox方式
    c4 = st.toggle(label='   ', value='True')   #toggle方式

df_map = pd.DataFrame()

if c1:
    df_map = pd.concat([df_map, df1], ignore_index=True)
if c2:
    df_map = pd.concat([df_map, df2], ignore_index=True)
if c3:
    df_map = pd.concat([df_map, df3], ignore_index=True)
if c4:
    df_map = pd.concat([df_map, df4], ignore_index=True)

df_map = df_map.rename(columns={'纬度':'LAT', '经度':'LON'})

st.map(df_map)